package com.example.binpacking.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.binpacking.model.FunInterview;
import com.example.binpacking.model.Interview;
import com.example.binpacking.model.InterviewContent;
import com.example.binpacking.model.SubjectView;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface FunInterviewMapper {

    @Select("SELECT * FROM tbl_fun_interview WHERE loginid = #{loginid} and isdeleted=0")
    Page<Interview> selectByLoginid(Page<Interview> page, @Param("loginid") String loginid);


    @Select("SELECT * FROM tbl_fun_interview WHERE loginid = #{loginid} and id=#{id}")
    FunInterview selectByLoginidAndId(@Param("loginid") String loginid, @Param("id")String id);

    @Update("UPDATE tbl_fun_interview set isdeleted=1\n" +
            "WHERE loginid=#{loginid} and id =#{id};")
    int  deleteLoginidAndId(@Param("loginid")String loginid,@Param("id")String id);

    @Select("SET @max_id = (SELECT IFNULL(MAX(id), 0) FROM tbl_fun_interview)")
    void initializeMaxId();

    @Insert(
            "INSERT INTO tbl_fun_interview (id,orderid, loginid,rightid)\n" +
                    "            SELECT MAX(orderid) + 1 + 20000000000,MAX(orderid) + 1, #{loginid},#{rightid}\n" +
                    "            FROM tbl_fun_interview;")
    int insertLoginidAndrightid(@Param("loginid")String loginid,@Param("rightid")String rightid);

    @Select("SELECT *,(select iscalculated from tbl_fun_interview where id=(SELECT MAX(id) FROM tbl_fun_interview)) as calculatedTip,(select name from tbl_login_interview where loginid=#{loginid}) as name   FROM tbl_fun_interview where id = (SELECT MAX(id) FROM tbl_fun_interview)")
//    @Select("SELECT * from tbl_fun_interview limit 1")
    List<FunInterview> select(@Param("loginid")String loginid,@Param("rightid")String rightid,@Param("id")String id);
//    @Select("select  from tbl_fun_interview where loginid=#{loginid} and rightid =#{rightid}; ")
//    String selectId(@Param("loginid")String loginid,@Param("rightid")String rightid);
    @Select("select MAX(orderid) from tbl_fun_interview; ")
    Long selectBegin();

    @Insert("INSERT INTO tbl_fun_interview (id,orderid, loginid,rightid)\n" +
                    "values (23000000001,3000000001, #{loginid},#{rightid})\n")
    int insertBegin(@Param("loginid")String loginid,@Param("rightid")String rightid);

    @Select("select id from tbl_fun_interview where loginid=#{loginid} LIMIT 1; ")
    String selectInterviewId(@Param("loginid")String loginid);
    @Update("UPDATE tbl_fun_interview set iscalculated=1 WHERE loginid=#{loginid} and id =#{id};")
    int updateByIdAndLoginid(@Param("loginid")String loginid,@Param("id")String id);

    @Select("SELECT * FROM tbl_fun_interview WHERE loginid = #{loginid} and id=#{id}")
    List<FunInterview> selectByLoginidAndInterviewId(@Param("loginid") String loginid, @Param("id")String id);

    @Select("SELECT * FROM tbl_fun_interview WHERE  id=#{id}")
    List<FunInterview> selectByInterviewId( @Param("id")String id);
    @Select("select loginid from tbl_fun_interview where id=#{id}")
    String selectLoginid(@Param("id")String id);

    @Select("SELECT id FROM tbl_fun_interview WHERE  rightid=#{rightid}")
    String selectByRightid( @Param("rightid")String rightid);


}
